<%
/**
 *      机构的地址本Frame
 *      含是否多选的参数
 *
 *  $Author: amon_lei $
 *  $Date: 2005/01/01 14:01:33 $
 *  $Revision: 1.1 $ 
 *  created in 2004-12-12
 */
%>
<%@ include file = "/common/ini.jsp"%>
<%@ include file = "/common/_log4j.jsp"%> 
<%@ include file = "/common/_ApplicationContext_init.jsp"%> 

<html>
        <%@ include file = "/tree_css_js_img/_xtree_css.jsp"%>
        <%@ include file = "/tree_css_js_img/_xtree_js.jsp"%>
        <%@ include file = "/common/AddressList/js/_AList_Frame_js_.jsp"%>
        <%@ include file = "_public_String_makeNoRootNodeView_Str_id_Str_name_Str_nodeType_Str_onclickJS_Str_superId_Str_openImg_Str_closeImg_.jsp"%>
        <%@ include file = "_public_String_makeRootNodeView_Str_id_name_Str_nodeType_Str_onclickJS_Str_openImg_Str_closeImg_Str_visibleImg.jsp"%>
<%
        //显示Org树图
        OrgManager orgManager = (OrgManager)applicationContext.getBean("orgManager");
        logger.info("开始构造地址本frame - org2post");
        Org rootOrg = new Org();
        if( !request.getParameter("rootOrgCode").equals("null"))
        {
            logger.debug("根结点 != null");
            String rootOrgCode = request.getParameter("rootOrgCode");
            Org org = orgManager.getByCode(rootOrgCode);
            if(org == null)
            {
                logger.error("code为" + rootOrgCode + "的机构不存在");
                return;
            }
            rootOrg.addOrg(org);
        }
        else
        {
            logger.debug("根结点 == null");
            List orgs = orgManager.findOrgs(rootOrg.getId());
            logger.debug("节点个数：" + orgs.size());
            rootOrg.addSubOrgs(new LinkedHashSet(orgs));
        }
        Object[] orgs = rootOrg.getAllSubOrgs().toArray();
        
%>
        <script>  
                 <%
                        out.print(this.makeRootNodeView("ORG",
                                                        rootOrg.getId(),
                                                        WebPath + "/tree_css_js_img/images/root.gif")
                                 );
                        for(int i = 0; i < orgs.length; i ++)
                        {
                            Org org = (Org)orgs[i];
                            out.print(this.makeNoRootNodeView(org.getId(),
                                                              org.getName(),
                                                              "ORG",
                                                              "select('" + org.getId() + "','" + org.getName() + "','ORG')",
                                                              "ORG",
                                                              org.getSuperOrg().getId(),
                                                              WebPath + "/tree_css_js_img/images/org.gif",
                                                              WebPath + "/tree_css_js_img/images/org.gif")
                                     );
                            Object[] posts = org.getPosts().toArray();
                            for(int j = 0; j < posts.length; j ++)
                            {
                                Post post = (Post)posts[j];
                                out.print(this.makeNoRootNodeView(post.getId(),
                                                                  post.getName(),
                                                                  "POST",
                                                                  "select('" + post.getId() + "','" + post.getName() + "','POST')",
                                                                  "ORG",
                                                                  org.getId(),
                                                                  WebPath + "/tree_css_js_img/images/post_open.png",
                                                                  WebPath + "/tree_css_js_img/images/post_close.png")
                                        );
                            }// for( j  
                                     
                        }// for( i 
                        
                %>
                document.write(Node0);
        </script>
</html>
